﻿#region 命名空间

using System;
using System.Text;
using System.Web.UI.WebControls;
using WinnerCMS.BLL;
using WinnerCMS.Common;
using WinnerCMS.Model;
using WinnerCMS.Model.Attribute;

#endregion

namespace WinnerCMS.WebUI.Admin.Common
{
    [Access("257007")]
    public partial class Recyclebin : WebFactory.PageBase
    {
        private CoreManage _myBll;

        protected void Page_Load(object sender, EventArgs e)
        {
            this._myBll = new CoreManage();

            if (!IsPostBack)
            {
                BindList(1);
                this.BC_Path.Items.Add(new ListItem("回收站", "Recyclebin.aspx"));
            }
        }


        private void BindList(int pageNo)
        {
            this.GV_List.EmptyDataTemplate = GetTemplate(this);

            var pp = new PagingParam
            {
                PageNo = pageNo,
                PageSize = this.PageNavigation1.PageSize
            };
            this.GV_List.DataSource = this._myBll.RecyclebinList(pp);
            this.GV_List.DataBind();
            this.PageNavigation1.RecordCount = pp.RecordCount;

            if (this.GV_List.Rows.Count <= 0)
            {
                this.btnDelSeletedID.Enabled = false;
                this.btnDelALL.Enabled = false;
                this.btnTrunSelectID.Enabled = false;
                this.btnTrunAll.Enabled = false;
            }
        }

        protected void DelSeletedID_Click(object sender, EventArgs e)
        {
            this._myBll.DeleteAndUndelete(GetSelectedRow.GetIDs(this.GV_List), 1, this.UpdatePanel1);
            BindList(1);
        }

        protected void DelALL_Click(object sender, EventArgs e)
        {
            this._myBll.DeleteAndUndelete(0.ToString(), 4, this.UpdatePanel1);
            BindList(1);
        }

        protected void TrunSelectID_Click(object sender, EventArgs e)
        {
            this._myBll.DeleteAndUndelete(GetSelectedRow.GetIDs(this.GV_List), 3, this.UpdatePanel1);
            BindList(1);
        }

        protected void TrunAll_Click(object sender, EventArgs e)
        {
            this._myBll.DeleteAndUndelete(0.ToString(), 2, this.UpdatePanel1);
            BindList(1);
        }

        protected void GV_List_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            var ID = this.GV_List.DataKeys[e.RowIndex].Value.ToString();

            this._myBll.DeleteAndUndelete(ID, 1, this.UpdatePanel1);

            BindList(1);
        }

        protected void GV_List_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Disdeleted")
            {
                var Index = Convert.ToInt32(e.CommandArgument);
                var ID = this.GV_List.DataKeys[Index].Value.ToString();

                this._myBll.DeleteAndUndelete(ID, 3, this.UpdatePanel1);
                BindList(1);
            }
        }

        protected string MyLink(object contentTitle, int intLong, object ID, object hits)
        {
            var strTitle = MyString.Left(contentTitle.ToString(), intLong);

            var winner = new StringBuilder();
            winner.Append("<a onclick='return false;' href='#'");
            winner.Append(" title=\"标题：");
            winner.Append(contentTitle);
            winner.Append("\n点 击 数：");
            winner.Append(hits);
            winner.Append("\">");
            winner.Append(strTitle);
            winner.Append("</a>");

            return winner.ToString();
        }

        protected void PageNavigation1_PageChanging(object src, WebControls.PageChangingEventArgs e)
        {
            BindList(e.NewPageIndex);
        }
    }
}